<?

Smutty_Main::loadClass( 'Smutty_Database_MySQL_Result' );

/**
 *  singleton for the database
 *
 */

class Smutty_Database_MySQL extends Smutty_Database {

	var $cnn = null;

	function connect() {
		$cfg = Smutty_Config::getInstance();
		$this->cnn = mysql_connect(
			$cfg->get('db.host'),
			$cfg->get('db.username'),
			$cfg->get('db.password')
		);
		mysql_select_db( $cfg->get('db.name'), $this->cnn );
	}

	function query( $sql ) {
		$res = mysql_query( $sql, $this->cnn );
		return $res ? new Smutty_Database_MySQL_Result($res) : false;
	}

	function update( $sql ) {
		return mysql_query($sql,$this->cnn) ? true : false;
	}

	function quote( $string ) {
		return preg_replace( '/\'/', '\\\'', $string );
	}

	function getInsertId() {
		return mysql_insert_id( $this->cnn );
	}

	function getError() {
		return mysql_error( $this->cnn );
	}

	function getCurrentDate() {
		return date( $this->getDateFormat() . ' h:i:s' );
	}

	function getFieldsSql( $table ) {
		return " desc `$table` ";
	}

	function getDateFormat() {
		return 'Y-m-d';
	}

}

?>